#include "Queen.h"
#include "../Game/Engine.h"
#include "../Board/Chessboard.h"
#include "../Board/Square.h"

namespace Core
{

	Queen::Queen(Player * player, Square * square)
		:Piece(player, square)
	{
	}


	Queen::~Queen(void)
	{
	}

	std::string Queen::name() const { return "Queen"; }
	ChType Queen::type() const { return ChType::ChQueen; }

	//Move * Queen::canMove(Square * dst)
	//{
	//	Move * mv = Move::createMove(this, dst);
	//	
	//	
	//	return mv;
	//}


	void Queen::updateValidMoves()
	{
		int r = this->square()->row();
		int c = this->square()->column();
		
		considerForValidMoves(r+1, c, true);
		considerForValidMoves(r-1, c, true);
		considerForValidMoves(r, c+1, true);
		considerForValidMoves(r, c-1, true);

		considerForValidMoves(r+1, c+1, false);
		considerForValidMoves(r+1, c-1, false);
		considerForValidMoves(r-1, c+1, false);
		considerForValidMoves(r-1, c-1, false);

	}

	void Queen::considerForValidMoves(int r2, int c2, bool direct)
	{
		const Chessboard * brd = Engine::instance()->chessboard();
		Piece * p = NULL;
		try
		{
			if(direct)
				p = brd->findPieceDirect(square()->row(), square()->column(), r2, c2, true, &_validMoves); // might throw exception
			else
				p = brd->findPieceDiagonal(square()->row(), square()->column(), r2, c2, true, &_validMoves); // might throw exception
		}
		catch(...) { }
	}

}
